package cn.haiway.drools.config;

import com.mongodb.MongoClientOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MongoConfig {

    @Value("${spring.data.mongodb.timeout}")
    private int timeout;


    @Bean
    MongoClientOptions mongoClientOptions() {
        MongoClientOptions.Builder builder = MongoClientOptions.builder();

        builder.maxWaitTime(timeout);
        builder.connectTimeout(timeout);
        builder.heartbeatConnectTimeout(timeout);
        builder.maxConnectionLifeTime(timeout);
        builder.maxConnectionIdleTime(timeout);
        builder.serverSelectionTimeout(timeout);

        return builder.build();
    }

}
